/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.gac.gacmod.model;

import org.gac.gacmod.messages.MessageCollection;
import org.gac.gacmod.genetics.*;

/**
 *
 * @author Tomek
 */
public abstract class Step {
    protected String _name;
    protected IStepStateListener _changeListener;
    private IStepStateListener _suspendedChangeListener;
    protected Step _parent;
    
    public Step( Step parent, String name )
    {
        _name = name;
        _parent = parent;
    }

    public Step()
    {
        this( null );
    }
    
    public Step( String name ){
        this( null, name);
    }
    
    public String getName()
    {
        return _name;
    }
    
    public void setName( String newName )
    {
        _name = newName;
        if (_changeListener != null)
        {
            _changeListener.StepStateChanged(Step.this);
        }
    }
    
    public abstract ExecutionOutput Run( ExecutionInput input);
    public abstract void Validate( MessageCollection messages );
    
    public void Configure()
    {
        
    }
    
    public void setStepChangeListener( IStepStateListener listener )
    {
        _changeListener = listener;
    }
    
    public void suspendEvents()
    {
        _suspendedChangeListener = _changeListener;
        _changeListener = null;
    }
    
    public void resumeEvents()
        {
            _changeListener = _suspendedChangeListener;
        }
        
    public Step getParent()
    {
        return _parent;
    }
    
    public void setParent( Step parent )
    {
        _parent = parent;
    }
    
    public Step getRootStep()
    {
        Step result = this;
        while( result._parent != null )
        {
            result = result._parent;
        }
        return result;
    }

}
